package com.example.dou2204.utils.aspect;

import android.content.Intent;

import androidx.activity.result.contract.ActivityResultContracts;

import com.blankj.utilcode.util.SPUtils;
import com.blankj.utilcode.util.ToastUtils;
import com.example.dou2204.App;
import com.example.dou2204.login.LoginActivity;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;

@Aspect
public class AspectCheckLogin {
    @Pointcut("execution(@com.example.dou2204.utils.aspect.CheckLogin * *(..))")
    public void check(){}
    @Around("check()")
    public void aroundCheck(ProceedingJoinPoint point) throws Throwable {
        String token = SPUtils.getInstance().getString("token");
        if(token.isEmpty()){
            ToastUtils.showLong("您还未登录，请去登录");
            App.getContext().startActivity(new Intent(App.getContext(), LoginActivity.class));
        }else {
            point.proceed();
        }
    }
}
